package EA.testproblems;
import EA.*;

/**
<table border="0" cellpadding="2" cellspacing="0">
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem description</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top" width="200"><b>Name:</b></td>
  <td valign="top">Rastrigin F1 50D</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Nickname:</b></td>
  <td valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Intended usage:</b></td>
  <td valign="top">Test of multimodal on problems with extremely many peaks.</td>
</tr>

<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem details</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Function:</b></td>
  <td valign="top"> 5*10 + Sum_(i=1)^5 (x_i^2 - 10*cos(2*pi*x_i)</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Ranges:</b></td>
  <td valign="top">x_i = [-5.12:5.12] </td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Type:</b></td>
  <td valign="top">Minimization</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of maxima:</b></td>
  <td valign="top">More than 50</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of minima:</b></td>
  <td valign="top">More than 50</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optima radius:</b></td>
  <td valign="top">0.2</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optima descriptions:</b></td>
  <td valign="top">The minima are located near (0,0,...,0)</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Known optima:</b></td>
  <td valign="top">
  GMIN(0,...,0), lmin(+-k,+-k,+-k,+-k,...,+-k), where k=0,1,2,3,4,5<br>
  Lowest value when all but one is 0<br>

<br><font size=1>Capital letters 
means that the precise optima is known, lowercase letters is the best known 
so far.</font></td>
</tr>
<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Plotting details</b></td>
</tr>

<tr bgcolor="#e0e0e0">
  <td valign="top"><b>GNUPlot code:</b></td>
  <td valign="top">
  set hidden3d<br>
  set isosamples 70<br>
  set view 60,20<br>
  splot [-10:3] [-3:10] x*x - 10*cos(2*pi*x) + 10 + y*y - 10*cos(2*pi*y) + 10<br>
</td>
</tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Latex code:</b></td>
   <td valign="top">
   Rastrigin F1 (20 dimensions):<br>
   \[<br>
   f(\overline{x}) = 200 + \sum_{i=1}^{20} x_i^2 - 10\cdot{}cos(2\pi{}x_i)\\[-2mm]<br>
   \]<br>
   where\\<br>
   \vspace*{-2mm}<br>
   \[<br>
   -5.12\leq{}x_i\leq{}5.12<br>
   \]<br>
   </td></tr>

</table>

*/
public class RastriginF1_50D extends NumericalProblem
{
  // Easier way to build max
  private double[][] lmax =  new double[0][50];
  private double[][] lmin =  {
			      {0,0,0,0,0,0,0,0,0,0,
			       0,0,0,0,0,0,0,0,0,0,
			       0,0,0,0,0,0,0,0,0,0,
			       0,0,0,0,0,0,0,0,0,0,
			       0,0,0,0,0,0,0,0,0,0}};

  public RastriginF1_50D()
    {
      super();

      double[] optimas;
      int i,j;

      name = "Rastrigin F1 - 50D";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		double sumres = 0;
		int idx;

		for (idx=0;idx<realpos.length; idx++) {
		  sumres += realpos[idx]*realpos[idx] - 10*Math.cos(2*Math.PI*realpos[idx]);
		}
		return 10*realpos.length + sumres;
	      };
	  };
      dimensions = 50;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[dimensions];
      for (i=0;i<dimensions;i++) {
	intervals[i] = new Interval(-5.12,5.12);
      }

      // Set up known maxima
      knownmaxima = new NumericalOptimum[lmax.length];
      for (i=0;i<lmax.length;i++) {
	optimas = new double[dimensions];
        for (j=0;j<dimensions;j++) {
	  optimas[j] = lmax[i][j];
	}
	knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
      }

      // Set up known minima
      knownminima = new NumericalOptimum[lmin.length];

      for (i=0;i<lmin.length;i++) {
	optimas = new double[dimensions];
        for (j=0;j<dimensions;j++) {
	  optimas[j] = lmin[i][j];
	}
	knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
      }
    }
}



